#include "array.h"
#include "sparse.h"
#include "parser.h"
#include "vp.h"
#include <getopt.h>
#include <cstdio>
#include <cstdlib>
#include <fstream>

using namespace std;

int main(int argc, char* argv[]){
    Array<real> predv;
    Array<real> preda;
    const char* modelfile="vpmodel";
    const char* predfile="vppred";
    const char* help="Usage: %s [ -m modelfile ] [ -o outputfile ] testset\n";
    int option;
    while((option=getopt(argc,argv,"m:o:"))!=EOF){
        switch(option){
            case 'm': modelfile=optarg; break;
            case 'o': predfile=optarg; break;
            case '?': fprintf(stderr,help,argv[0]); exit(1); break;
        }
    }
    if(argv[optind]==0){
        fprintf(stderr,help,argv[0]);
        exit(1);
    }
    ofstream ofs(predfile);
    Array<vector*> s;
    parser p(argv[optind]);
    p.parse(s);
    perceptron vp;
    vp.read(modelfile);
    vp.test(s,predv,preda);
    vp.write(modelfile);
    for(int i=0; i<s.size(); i++){
        ofs<<s[i]->getClass()<<" "<<predv[i]<<" "<<preda[i]<<endl;
    }
    return 0;
}
